home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10349 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  45 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!news1!ts02-and-07
  3. From: dlmiller@iquest.net (Doug & Rose Miller)
  4. Subject: Re: NEwbie: How to return a multi-dimensional array from function?
  5. X-Nntp-Posting-Host: ts02-and-07.iquest.net
  6. Message-ID: <DoE3K0.H4y@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Network Services
  9. X-Newsreader: News Xpress Version 1.0 Beta #2.1
  10. References: <mjs.826298629@hubcap> <4ib78s$6gv@news.bridge.net> <4ic3p3$cl5@news.xs4all.nl> <4ic8pj$c99@news.bridge.net>
  11. Date: Sun, 17 Mar 1996 02:09:11 GMT
  12.  
  13. psycho@bridge.net (Gary Thompson) wrote:
  14. +falstaff@xs4all.nl (Falstaff) wrote:
  15. +
  16. +>psycho@bridge.net (Gary Thompson) writes:
  17. +
  18. +>>>Two things: (1) If you are going to use the value of tmp outside of Foo(),
  19. +>>>then you need to declare
  20. +>>>    static tmp[10][5];
  21. +>>>Otherwise the storage may disappear when you return from Foo().
  22. +
  23. +>>No, declaring it as static will only retain the value in the foo() function, if
  24. +>>you call it more than once.  You CANNOT use a value declared in a subfunction in
  25. +>>MAIN.  You would have to remove both TMP declarations from MAIN and FOO and
  26. +>>declare the thing globally outside of main.
  27. +
  28. +>WRONG!!!
  29. +
  30. +>If you declare a function
  31. +
  32. +>int *demo(void)
  33. +>{  static int n=0;
  34. +>   n++;
  35. +>   return &n;
  36. +>}
  37. +
  38. +>the caller can use the static variable until the next time your function
  39. +>is called.  This is how the standard library function tmpnam() returns,
  40. +>for example.
  41. +
  42. +Well, of course it will work in your example... you returned the value.
  43.  
  44. returning the value _is_ what the original post asked for, so what's your beef?
  45.